//
//  AddImageCollectionViewCell.m
//  VideoData
//
//  Created by pro1 on 2019/3/7.
//  Copyright © 2019 pro1. All rights reserved.
//

#import "AddImageCollectionViewCell.h"

@interface AddImageCollectionViewCell ()

@property (strong,nonatomic) UIImageView *contentImage;
@property (strong,nonatomic) UILabel *contentLabel;
@property (strong,nonatomic) UIImageView *selectImage;

@end

@implementation AddImageCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 4;
        self.layer.borderWidth = 0.5;
        
        self.layer.borderColor = [UIColor colorWithRed:151/255.0 green:151/255.0 blue:151/255.0 alpha:0.5].CGColor;//默认颜色
//        self.layer.borderColor = [UIColor colorWithRed:243/255.0 green:166/255.0 blue:51/255.0 alpha:1.0].CGColor;//选中颜色
        
        [self addSubview:self.contentLabel];
        [self addSubview:self.contentImage];
        [self addSubview:self.selectImage];
        
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.left.right.equalTo(self).offset(0);
        }];
        [_contentImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.left.right.equalTo(self).offset(0);
        }];
        
        [_selectImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.right.equalTo(self).offset(-2.5);
            make.width.height.offset(22);
        }];
    }
    return self;
}

- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    _selectImage.hidden = !selected;
    if (selected) {
        self.layer.borderColor = [UIColor colorWithRed:243/255.0 green:166/255.0 blue:51/255.0 alpha:1.0].CGColor;//选中颜色
    }
    else{
        self.layer.borderColor = [UIColor colorWithRed:151/255.0 green:151/255.0 blue:151/255.0 alpha:0.5].CGColor;//默认颜色
    }
}

- (UIImageView *)contentImage{
    if (!_contentImage) {
        _contentImage = [[UIImageView alloc] init];
        _contentImage.contentMode = UIViewContentModeScaleAspectFill;
        _contentImage.clipsToBounds = YES;
    }
    return _contentImage;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.text = @"留光";
        _contentLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _contentLabel;
}

- (UIImageView *)selectImage{
    if (!_selectImage) {
        _selectImage = [[UIImageView alloc] init];
        _selectImage.contentMode = UIViewContentModeScaleAspectFit;
        _selectImage.image = [UIImage imageNamed:@"选择_sel"];
    }
    return _selectImage;
}

- (void)setStyle:(CellStyle)style{
    _style = style;
    
    switch (_style) {
        case CellStyleFont:
        {
            self.backgroundColor = [UIColor whiteColor];
            self.contentImage.hidden = YES;
            self.contentLabel.hidden = NO;
        }
            break;
        case CellStyleBGColor:
        {
            self.backgroundColor = UIColorMake(arc4random()%255, arc4random()%255, arc4random()%255);
            self.contentImage.hidden = YES;
            self.contentLabel.hidden = YES;
        }
            break;
        case CellStyleImage:
        {
            self.backgroundColor = [UIColor grayColor];
            self.contentImage.hidden = NO;
            self.contentLabel.hidden = YES;
        }
            break;
        case CellStyleTheSeal:
        {
            self.backgroundColor = [UIColor whiteColor];
            self.contentImage.hidden = NO;
            self.contentLabel.hidden = YES;
        }
            break;
        case CellStyleTemplate:
        {
            self.backgroundColor = [UIColor whiteColor];
            self.contentImage.hidden = NO;
            self.contentLabel.hidden = YES;
        }
            break;
            
        default:
            break;
    }
}

- (void)setContentValue:(id)contentValue{
    _contentValue = contentValue;
    if (_contentValue) {
        if ([_contentValue isKindOfClass:[UIFont class]]) {
            _contentLabel.font = _contentValue;
        }
        else if ([_contentValue isKindOfClass:[UIColor class]]){
            self.backgroundColor = _contentValue;
        }
        else if ([_contentValue isKindOfClass:[NSString class]]){
            self.contentImage.image = [UIImage imageNamed:_contentValue];
        }
        else if ([_contentValue isKindOfClass:[NSURL class]]){
            [_contentImage sd_setImageWithURL:_contentValue];
        }
        else if ([_contentValue isKindOfClass:[UIImage class]]){
            _contentImage.image = _contentValue;
        }
    }
}

@end
